<template>
  <a-modal
    title="新建"
    :width="840"
    :visible="visible"
    :confirmLoading="loading"
    @ok="modalOk"
    @cancel="() => { $emit('cancel') }"
  >
    <a-spin :spinning="loading">
      <a-form :form="form" v-bind="formLayout">
        <!-- 检查是否有 id 并且大于0，大于0是修改。其他是新增，新增不显示主键ID -->
        <a-form-item v-show="true" label="主键ID">
          <a-input v-decorator="['id', { initialValue: 0 }]" disabled />
        </a-form-item>
      </a-form>
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :row-key="(record)=>record.id"
        :showPagination="false"
      >
      </s-table>
    </a-spin>
  </a-modal>
</template>

<script>
// 审核状态 0=待审核 1=待开票 2=待发行 3=已完成
import pick from 'lodash.pick'
import { getDeliverylies } from '@/api/manage'
import { STable } from '@/components'
const fields = ['id']

export default {
  name: 'TicketDetail',
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    loading: {
      type: Boolean,
      default: () => false
    },
    model: {
      type: Object,
      default: () => null
    }
  },
  data () {
    this.formLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 }
      }
    }
    return {
      form: this.$form.createForm(this),
      loadData: (parameter) => {
        console.log(this.model)
        return getDeliverylies(this.model.id).then(res => {
          const records = []
          records.push(res.data.record)
          return {
            data: records,
            totalCount: parseInt(res.headers['x-count']),
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize
          }
        })
      },
      recordStationList: [],
      columns: [
        {
          title: '#',
          dataIndex: 'id'
        },
        {
          title: '发票流水号',
          dataIndex: 'fpqqlsh'
        },
        {
          title: '发票审核状态',
          dataIndex: 'submitState'
        },
        {
          title: '发票金额',
          dataIndex: 'totalPrice'
        }
      ],
      memberList: [],
      customerList: [],
      deliveryList: [],
      deliveryDetailList: []
    }
  },
  components: {
    STable
  },
  created () {
    // 防止表单未注册
    fields.forEach(v => this.form.getFieldDecorator(v))
    // 当 model 发生改变时，为表单设置值
    const _self = this
    this.$watch('model', () => {
      this.form = this.$form.createForm(this)
      if (this.visible) {
        // getStationRecord({ deliveryId: this.model.id }).then(res => {
        //   this.recordStationList = res.data
        // })
        this.$refs.table.refresh(true)
        _self.$nextTick(() => {
          this.model && this.form.setFieldsValue(pick(this.model, fields))
        })
      }
    })
  },
  methods: {
    modalOk () {
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
